package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.BaseStaffDao;
import com.itheima.edu.info.manager.dao.OtherStaffDao;
import com.itheima.edu.info.manager.dao.StaffDao;
import com.itheima.edu.info.manager.domain.Staff;
import com.itheima.edu.info.manager.util.StaffFactory;

public class StaffService {
    BaseStaffDao staffDao = StaffFactory.getStaffDao();

    public boolean isFull() {
        //纪录staff数组元素非空的个数
        int num = 0;
        Staff[] staffs = staffDao.findAllStaff();
        if (staffs.length != 0){
            for (int i = 0; i < staffs.length; i++) {
                if (staffs[i] != null){
                    num++;
                }
            }
            if (num >= staffs.length){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }
    }

    public boolean isExist(String sid) {
        Staff[] staffs = staffDao.findAllStaff();
        for (int i = 0; i < staffs.length; i++) {
            if (staffs[i] != null && sid.equals(staffs[i].getId())){
                return true;
            }
        }
        return false;
    }

    public boolean addStaff(Staff staff) {
        return staffDao.addStaff(staff);
    }

    public Staff[] findAllStaff() {
        Staff[] staffs = staffDao.findAllStaff();
        return staffs;
    }

    public boolean staffExist() {
        Staff[] staffs = staffDao.findAllStaff();
        for (int i = 0; i < staffs.length; i++) {
            if (staffs[i] != null){
                return true;
            }
        }
        return false;
    }

    public boolean sIdExist(String sId) {
        return staffDao.sIdExist(sId);
    }

    public void deleteStaff(String sId) {
        staffDao.deleteStaff(sId);
    }

    public void updateStaff(Staff updateStaff) {
        staffDao.updateStaff(updateStaff);
    }
}
